﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuKou.Common.Domains;
using LuKou.Common.Services;
using LuKou.Member.Domains;
using LuKou.Shopspace.Domains;
using LuKou.Shopspace.Services;
using LuKou.Web.BLL.Service;

namespace LuKou.Web.BLL.Extensions
{
    public static class ShopExt
    {
        private static IShopSvr shop_svr;
        private static IGoodsSvr goods_svr;

        static ShopExt()
        {
            shop_svr = ServiceHelper.Get<IShopSvr>("IShopSvr");
            goods_svr = ServiceHelper.Get<IGoodsSvr>("IGoodsSvr");
        }

        /// <summary>
        /// 分页获取店铺下商品数据
        /// </summary>
        /// <param name="shop"></param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">第页大小</param>
        /// <returns></returns>
        public static List<Goods> GetGoodsList(this Shop shop, int pageIndex, int pageSize = 10)
        {
            if (pageIndex < 1) pageIndex = 1;

            GoodsQueryParam param = new GoodsQueryParam();
            param.AddParamOfShopID(shop.ID);
            return goods_svr.GetGoodsList(param, true, (pageIndex - 1) * pageSize, pageSize);
        }

        /// <summary>
        /// 获取店铺下所有商品的总数
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        public static long GetGoodsCount(this Shop shop)
        {
            GoodsQueryParam param = new GoodsQueryParam();
            param.AddParamOfShopID(shop.ID);
            return goods_svr.GetGoodsCount(param);
        }

        /// <summary>
        /// 获取店铺下的推荐商品
        /// </summary>
        /// <param name="shop"></param>
        /// <param name="count">获取商品的数量</param>
        /// <returns></returns>
        public static List<Goods> GetRecommendGoods(this Shop shop, int count)
        {
            GoodsQueryParam param = new GoodsQueryParam();
            param.AddParamOfShopID(shop.ID);
            param.AddParamOfIsRecommend(true);
            return goods_svr.GetGoodsList(param, true, 0, count);
        }

        /// <summary>
        /// 获取店铺的用户信息
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        public static User GetUserInfo(this Shop shop)
        {
            return UserService.GetUserInfoById(shop.UserID);
        }

        /// <summary>
        /// 获取店铺对应等级信息
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        public static ShopGrade GetShopGrade(this Shop shop)
        {
            return ServiceHelper.Get<IShopGradeSvr>("IShopGradeSvr").GetShopGradeDetail(shop.ShopGradeID, true);
        }
    }
}
